package com.qinggeng.project.api.controller;

import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.project.api.dto.UserAccountRecordDTO;
import com.qinggeng.project.api.security.annotation.LoginRequired;
import com.qinggeng.project.api.security.utils.ApiUtils;
import com.qinggeng.project.system.domain.UserAccountRecord;
import com.qinggeng.project.system.domain.vo.AccountInfoVO;
import com.qinggeng.project.system.domain.vo.WithdrawalVO;
import com.qinggeng.project.system.service.IUserAccountService;
import com.qinggeng.project.system.service.UserAccountRecordService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("${apiPath}/account")
@CrossOrigin
public class ApiUserAccountController {

    @Resource
    private IUserAccountService userAccountService;

    @Resource
    private UserAccountRecordService  userAccountRecordService;
    @GetMapping
    @LoginRequired
    public AjaxResult getAccountInfoVO(){
        Long userId=ApiUtils.getUserId();
        AccountInfoVO accountInfoVO= userAccountService.getAccountInfoVO(userId);
        return AjaxResult.success(accountInfoVO);
    }

    //转账到零钱明细
    @PostMapping("/listTransferToChangeDetails")
    @LoginRequired
    public AjaxResult listTransferToChangeDetails(UserAccountRecordDTO dto){
        Long userId=ApiUtils.getUserId();
        dto.setUserId(userId);
        List<UserAccountRecord> list=userAccountRecordService.listTransferToChangeDetails(dto);
        return AjaxResult.success(list);
    }

    //提现明细
    @PostMapping("/listWithdrawalDetails")
    @LoginRequired
    public AjaxResult listWithdrawalDetails(UserAccountRecordDTO dto){
        Long userId=ApiUtils.getUserId();
        dto.setUserId(userId);
        List<WithdrawalVO> list=userAccountRecordService.listWithdrawalDetails(dto);
        return AjaxResult.success(list);
    }

}
